home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.ada,comp.lang.c++,comp.lang.c,comp.lang.modula3,comp.lang.modula2,comp.lang.eiffel
- Subject: Re: Hungarian notation
- Date: 21 Jan 1996 10:02:24 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4dtv3gINNo9u@keats.ugrad.cs.ubc.ca>
- References: <30C40F77.53B5@swsbbs.com> <4cvu68$2jb@macaw.cyberport.com> <4d21og$iab@news.xmission.com> <4d2ok0$69s@beach.and.nl>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <4d2ok0$69s@beach.and.nl>, Jos A. Horsmeier <jos@and.nl> wrote:
- >Prefixing 'psz' to every zero terminated string is plain silly if we're
- >talking about, say, employee names or beer brand names; something like
- >'empnm' and 'beernm' should have been used instead. Only then, statements
- >like:
- >
- > if (!strcmp(empnmBoss, beernmMyFavBeer))
- >
- >trigger the reader that something fishy is going on here ... HN, as it
- >is used now, doesn't add any clarity to the code at all, i.e. the statement:
- >
- > if (!strcmp(pszBoss, pszMyFavBeer))
- >
- >just tells me that I want to compare my favorite beer and a boss's name,
- >which is silly too, but it's not the 'psz' prefix that rings a bell here;
- >it's just the 'Boss' and 'MyFavBeer' name parts that catch the eye.
-
- I agree. The "psz" is just a redundant prefix that pollutes the symbol table.
- If anyone wrote code with random consonants thrown in front of every perfectly
- good name, I'd fire them on the spot, and tell them to go rearrange their
- closet.
-
- >Just adding domain name prefixes to the names of objects doesn't help
- >anyone; notion of domains should be present in the language itself if
- >one really wants domains, instead of just comparable types as implemented
- >in the C language. Any (decent) C compiler feels perfectly fine if one
- >feeds it something like:
- >
- > #include <stdio.h>
- > #include <string.h>
- >
- > typedef char* empnm_t;
- > typedef char* beernm_t;
-
- Even that is going overboard. Someone will later see "empnm_t", and wonder what
- the heck it is. If you mean "char *", just say "char *". The typedef operator
- has its uses, but redefining simple types, like char * or int is not one of
- them. The chief advantage is that you can use it with structs so that you can
- eliminate having to write the struct keyword later on.
-
- I just wrote a 12000 line project that doesn't have one typedef in it (save for
- automatically generated XDR definitions). The code is easy to read; I can go
- back to it and understand precisely what is going on without hunting for nested
- definitions.
-
- I gave the code to another programmer who is doing a Windows interface, and he
- said that everything was nicely laid out for him, enabling him to incoroporate
- the bits in a short time.
-
- Typedef-like constructs are useful in poorly thought-out languages like Modula
- or Pascal, whose compilers can typically perform typechecks based only on name
- equivalence. That is to say, if I declare two types that are both integers, the
- compiler will say that the two types are not equivalent, because it goes only
- as far as to check the name. This is a cop out which simplifies doing one of
- the more difficult phases of compiler construction, which is type checking. It
- has nothing to do with implementing "domains", and everything to do with lazy
- compiler construction. Real compilers will detect structure equivalence between
- types so that you don't have to obfuscate your code with confusing type names.
- To implement domains, just lobotomize the compiler by removing the structure
- equivalence checking so that size_t and time_t become incompatible types.
- --
-
-